using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;
public partial class Ad_ManageCoupon : System.Web.UI.Page
{
   /// <summary>
   /// This page is created for manage Coupon for admin only.
   /// </summary>
   /// Author:Akash Saxena
   /// <param name="sender"></param>
   /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGrid(Convert.ToInt32(ddlType.SelectedValue));
        }

    }
    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindGrid(Convert.ToInt32(ddlType.SelectedValue));
    }
    /// <summary>
    ///This Function fills the grid according to selected value of dropdown i.e.Doctor/Dentist.
    /// </summary>
    /// Author : Vinayak Singh Rathore
    /// <param name="typeofDoctor"></param>
    public void BindGrid(int typeofDoctor)
    {
        lblMsg.Text = " ";
        Manager objManager = new Manager(true,"ConnectionString");
        DataSet objDataSet = new DataSet();
        SqlParameter[] objSqlParameter = new SqlParameter[1];
        objSqlParameter[0] = new SqlParameter("@DoctorType",SqlDbType.SmallInt);
        objSqlParameter[0].Value = typeofDoctor;// Convert.ToInt32(ddlType.SelectedValue);
        objDataSet = objManager.ExecuteQuery("GetCoupon", objSqlParameter, "coupon");
        if (objDataSet.Tables[0].Rows.Count > 0)
        {
            grdCoupon.DataSource = objDataSet;
            grdCoupon.DataBind();
        }
        else
        {
            grdCoupon.DataSource = objDataSet;
            grdCoupon.DataBind();
            lblMsg.Text = "Record Does Not Exist";
        }
    }
    protected void grdCoupon_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        Manager objManager = new Manager(true,"ConnectionString");
        if (e.CommandName == "DEL")
        {
            objManager.ExecuteQuery("Delete from coupons where SNO="+Convert.ToInt32(e.CommandArgument));   
        }
        if (e.CommandName == "IsActive")
        {
            SqlParameter[] objSqlParameter = new SqlParameter[1];
            objSqlParameter[0] = new SqlParameter("@SNO",SqlDbType.SmallInt);
            objSqlParameter[0].Value = Convert.ToInt32(e.CommandArgument);
            objManager.ExecuteQuery("ActiveInactiveCoupon", objSqlParameter);
        }
        objManager = null;
        BindGrid(Convert.ToInt32(ddlType.SelectedValue));
    }
   
}
